<?php
	require_once("../db_connect.php");

	$volunteer_information_id ="";
	$volunteer_information = "";

	if(array_key_exists("volunteer_information_id",$_GET))$volunteer_information_id  = htmlspecialchars($_GET['volunteer_information_id'],ENT_QUOTES,"UTF-8");
	if(array_key_exists("volunteer_information",$_POST))$volunteer_information = $_POST['volunteer_information'];

	if($volunteer_information==""){
		$sql = "DELETE FROM volunteer_information WHERE volunteer_information_id = ?";
		$stmt = $db->prepare($sql);
		$ary = ($volunteer_information_id);

		$db->execute($stmt, $ary);     //UPDATE文を実行

		if (PEAR::isError($db)) {       //SQLの実行に失敗すればここでエラー文を出力
	    	die($res->getMessage());
		}

		$sql = "DELETE FROM application WHERE volunteer_information_id = ?";
		$stmt = $db->prepare($sql);
		$ary = ($volunteer_information_id);

		$db->execute($stmt, $ary);     //UPDATE文を実行

		if (PEAR::isError($db)) {       //SQLの実行に失敗すればここでエラー文を出力
	    	die($res->getMessage());
		}

	}else{
			for($i=0;$i<count($volunteer_information);$i++){
				$sql = "DELETE FROM volunteer_information WHERE volunteer_information_id = ?";
				$stmt = $db->prepare($sql);
				$ary = (htmlspecialchars($volunteer_information[$i],ENT_QUOTES,"UTF-8"));

				$db->execute($stmt, $ary);     //UPDATE文を実行

				if (PEAR::isError($db)) {       //SQLの実行に失敗すればここでエラー文を出力
			    	die($res->getMessage());
				}
			$sql = "DELETE FROM application WHERE volunteer_information_id = ?";
			$stmt = $db->prepare($sql);
			$ary = (htmlspecialchars($volunteer_information[$i],ENT_QUOTES,"UTF-8"));

			$db->execute($stmt, $ary);     //UPDATE文を実行

			if (PEAR::isError($db)) {       //SQLの実行に失敗すればここでエラー文を出力
		    	die($res->getMessage());
			}
			}
	}
	header("Location: ../user_function/user_display_volunteer.php");
?>